package cn.iocoder.yudao.module.ad.plan.controller.admin;

import cn.iocoder.yudao.framework.business.audit.controller.AuditController;
import cn.iocoder.yudao.framework.business.audit.pojo.form.AuditSaveDTO;
import cn.iocoder.yudao.framework.business.basic.controller.*;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.ad.plan.service.AdminAdPlanService;
import cn.iocoder.yudao.module.ad.plan.vo.AdPlanQueryDTO;
import cn.iocoder.yudao.module.ad.plan.vo.AdPlanSaveDTO;
import cn.iocoder.yudao.module.ad.plan.vo.AdminAdPlanVO;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 广告投放计划")
@RestController
@RequestMapping("/ad/plan")
@Validated
public class AdPlanController implements CreateController<AdPlanSaveDTO>, UpdateController<AdPlanSaveDTO>, SimpleDeleteController, SimpleDetailController<AdminAdPlanVO>, PageController<AdminAdPlanVO, AdPlanQueryDTO>, AuditController {

    @Resource
    private AdminAdPlanService adminAdPlanService;

    @PreAuthorize("@ss.hasPermission('ad:plan:creative')")
    @Override
    public CommonResult<Long> create(AdPlanSaveDTO param) {
        return success(adminAdPlanService.create(param));
    }

    @PreAuthorize("@ss.hasPermission('ad:plan:creative')")
    @Override
    public CommonResult<Boolean> update(AdPlanSaveDTO param) {
        return success(adminAdPlanService.update(param));
    }

    @PreAuthorize("@ss.hasPermission('ad:plan:creative')")
    @Override
    public CommonResult<Boolean> delete(Long id) {
        return success(adminAdPlanService.delete(id));
    }

    @PreAuthorize("@ss.hasPermission('ad:plan:creative')")
    @Override
    public CommonResult<AdminAdPlanVO> getDetail(Long id) {
        return success(adminAdPlanService.getDetail(id));
    }

    @PreAuthorize("@ss.hasPermission('ad:plan:creative')")
    @Override
    public CommonResult<PageResult<AdminAdPlanVO>> getPage(Integer pageNo, Integer pageSize, AdPlanQueryDTO param) {
        PageResult<AdminAdPlanVO> page = adminAdPlanService.getPage(pageNo, pageSize, param);
        return success(page);
    }

    @PreAuthorize("@ss.hasAnyRoles('super_admin', 'platform_admin', 'tenant_admin')")
    @Override
    public CommonResult<Boolean> updateAudit(AuditSaveDTO reqVO) {
        adminAdPlanService.updateAudit(reqVO);
        return success(true);
    }

}
